// JavaScript Document
var setLoginHeight;
var setCheck;

$(function() {
	setLoginHeight = function(){
        var wth = $(window).height();
        var min_th = 600;
        var th = wth > min_th ? wth : min_th;
        $(".loginDiv").height(th);
    };

    setCheck = function(){
        if($(".blue_check").length == 0) return;
        $(".blue_check").iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal-blue',
            increaseArea: '20%' // optional
        });
    };
    setCheck();
    refresh();

    if($('#noticeFlag').val() == 'true') {
      showNotice ()
    }

    //国际化初始化
    if($('#languageFlag').val() == 'true' && $(".switch").text().trim() == '中文') {
      $(".loginCont .word div").addClass("wordMar");
    } else {
      $(".loginCont .word div").removeClass("wordMar");
    }
})

function enterKeyDown() {
  if(window.event.keyCode == 13) {
    doLogin();
  }
}
	
$(window).resize(function() {
	setLoginHeight();
	setCanvasWid();
});

function setCanvasWid() {
	wid = document.documentElement.clientWidth,
    hgt = document.documentElement.clientHeight;                      

	$("#canvas").width(wid);
	$("#canvas").height(hgt);
/*	$("#canvas").css("min-height",1200);
	$("#canvas").css("min-height",900);*/
}

function refresh(){
    document.getElementById("picCode").src = 'getValidCodeImage?t='+new Date().getTime();
}

function doLogin(){
	//校验
	//密码MD5加密
	var password=md5($("#password").val());
	//密码获取
    var secret=$("#validCode").val();
    password=EncryptUtil.hmacSha256(password,"tgit");
    password=EncryptUtil.hmacSha256(password,secret);
	$("#password").val(password);
	//提交
	$("form").submit();
	//防止重复提交
	$(".loginBtn").attr("disabled",true);
}

function Marquee1(){
  if(colee2.offsetTop-colee.scrollTop<=0){
    colee.scrollTop-=colee1.offsetHeight; //colee跳到最顶端
  }else{
    colee.scrollTop++;
  }
}

function showNotice () {
  var colspeed=150;
  var colee2=document.getElementById("colee2");
  var colee1=document.getElementById("colee1");
  var colee=document.getElementById("colee");
  if(!!colee1) {
    colee2.innerHTML=colee1.innerHTML; //克隆colee1为colee2
    var MyMar1=setInterval(Marquee1,colspeed)//设置定时器
    //鼠标移上时清除定时器达到滚动停止的目的
    colee.onmouseover=function() {clearInterval(MyMar1)}
    //鼠标移开时重设定时器
    colee.onmouseout=function(){MyMar1=setInterval(Marquee1,colspeed)}
  }
}
